package com.ui.design.main.base;

import android.app.Activity;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.ui.design.R;
import com.ui.design.main.constants.Constants;
import com.ui.design.utils.StatusbarUtil;
import com.ui.design.utils.StringUtils;

/**
 *tangxianfeng
 * 2021.7.25
 * 基础Activity
 */
public abstract class BaseActivity extends Activity {

    @Autowired
    String title="";
    @Autowired
    String blogurl="";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置布局
        setContentView(initLayout());
        ARouter.getInstance().inject(this);
        initView();
        initData();
        if (findViewById(R.id.title_blog)!=null){
            setTitleText(title,blogurl);
        }
        StatusbarUtil.darkMode(this, true);
    }

    /**
     * 设置title和博客地址
     * 需在layout里添加
      <include layout="@layout/title_include"/>
     * @param titleContent 设置title
     * @param blogurl 博客地址（可以不写）
     */
    public void setTitleText(String titleContent,String blogurl){
        TextView title=findViewById(R.id.title_content);
        ImageView back=findViewById(R.id.title_back);
        ImageView blog=findViewById(R.id.title_blog);

        if (title==null||back==null||blog==null){
            return;
        }
        title.setText(titleContent);
        back.setOnClickListener(v -> finish());
        if (StringUtils.isEmpty(blogurl)){
            blog.setVisibility(View.GONE);
        }else {
            blog.setVisibility(View.VISIBLE);
            blog.setOnClickListener(v -> gotoWebView(blogurl));
        }

    }

    private void gotoWebView(String url){
        ARouter.getInstance().build(Constants.Html).withString("webUrl",url).navigation();
    }
    /**
     * 初始化布局
     *
     * @return 布局id
     */
    protected abstract int initLayout();

    /**
     * 初始化控件
     */
    protected abstract void initView();

    /**
     * 设置数据
     */
    protected abstract void initData();




}
